package com.bdth.bdthmg.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.bdth.bdthmg.entity.User;
import com.bdth.bdthmg.service.UserService;
import com.bdth.bdthmg.vo.ResultVo;
import com.bdth.bdthmg.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2019/12/2.
 */
@RestController
@RequestMapping("/")
public class HomeController {
    @Autowired
    private UserService userService;

    @RequestMapping("index")
    public Map<String,String> index(){
        Map<String,String> result = new HashMap<>();
        result.put("value", "hello ,你好");
        return result;
    }

    @RequestMapping("list")
    public List<User> list(){
        EntityWrapper<User> entityWrapper = new EntityWrapper<>();
        entityWrapper.eq("state",1);
        List<User> list = userService.selectList(entityWrapper);
        return list;
    }

    @RequestMapping("save")
    public ResultVo save(UserVo param) {
        User bean = new User();
        BeanUtil.copyProperties(param,bean);
        bean.setBirthday(DateUtil.parse(param.getBirthday(),"yyyy-MM-dd"));
        bean.setLoadTime(new Date());
        bean.setState(1);
        boolean flag = userService.insert(bean);
        return ResultVo.getSuccess("创建成功");
    }
}
